package com.balloon.gateway.security.service;

import com.balloon.gateway.security.user.dao.SystemUserDao;
import com.balloon.gateway.security.user.entity.SystemUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
@Primary
public class UserDetailsServiceImpl implements ReactiveUserDetailsService {

    @Autowired
    private SystemUserDao systemUserDao;

    @Override
    public Mono<UserDetails> findByUsername(String username) throws UsernameNotFoundException {
        SystemUser byUsername = systemUserDao.findByUsername(username);
        if(byUsername == null){
            throw new UsernameNotFoundException("用户不存在");
        }
        return Mono.just(byUsername);
    }
}
